package com.example.driving.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.example.driving.R;
import com.example.driving.base.App;
import com.example.driving.ui.adapter.QuestionListAdapter;
import com.example.driving.ui.view.RingProgressBarView;
import com.example.driving.utils.SpannableWrap;

public class TimeFinishDialog extends Dialog {

    private Context context;
    private View mDialogView;
    private TextView tv_score, tv_cont, tv_level;
    private RingProgressBarView rpbv;

    public TimeFinishDialog(@NonNull Context context) {
        super(context);
        setCustomDialog(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        WindowManager windowManage = getWindow().getWindowManager();
        Display display = windowManage.getDefaultDisplay();
        WindowManager.LayoutParams lp = this.getWindow().getAttributes();
        lp.width = (int) (display.getWidth() * 0.8f);
        lp.height = (int) (display.getHeight() * 0.5f);

        getWindow().setAttributes(lp);
    }

    public void setCustomDialog(Context context) {
        this.context = context;
        mDialogView = View.inflate(context, R.layout.dialog_time_finish, null);
        tv_score = mDialogView.findViewById(R.id.score);
        tv_cont = mDialogView.findViewById(R.id.tv_cont);
        tv_level = mDialogView.findViewById(R.id.tv_level);

        int score = QuestionListAdapter.right_count;
        tv_score.setText(score + "");
        int text_primary = App.getmContext().getResources().getColor(R.color.ang_orange);
        int text_primary_color1 = App.getmContext().getResources().getColor(R.color.ang_09A6FE);
        int text_primary_color2 = App.getmContext().getResources().getColor(R.color.ang_FE6063);
        if (score < 60) {
            tv_level.setText("潜力学员");
            SpannableWrap.setText("正确率")
                    .append("较低")
                    .textColor(text_primary)
                    .append("，预计")
                    .append("成绩较低")
                    .textColor(text_primary)
                    .into(tv_cont);
        } else if (score >= 60 && score < 90) {
            tv_level.setText("良好学员");
            SpannableWrap.setText("正确率")
                    .append("良好")
                    .textColor(text_primary_color1)
                    .append("，预计")
                    .append("成绩良好")
                    .textColor(text_primary_color1)
                    .into(tv_cont);
        } else if (score >= 90 && score <= 100) {
            tv_level.setText("优秀学员");
            SpannableWrap.setText("正确率")
                    .append("不错")
                    .textColor(text_primary_color2)
                    .append("，预计")
                    .append("成绩不错")
                    .textColor(text_primary_color2)
                    .into(tv_cont);
        }
        rpbv = mDialogView.findViewById(R.id.rpbv);
        rpbv.setProgress(score);


        mDialogView.findViewById(R.id.bt_commit).setOnClickListener(v -> {
            TimeFinishDialog.this.dismiss();
        });
        setContentView(mDialogView);

    }


}
